<!-- 任务执行情况 -->
<template>
  <el-dialog title="菜品类目" :visible.sync="dialogVisible" @close="$emit('update:visible',false)"
             :close-on-click-modal="false">
    <div class="cateBody">
      <el-form label-width="100px">
        <el-form-item label="类目名称">
          <el-input v-model="cateNameV" auto-complete="off" placeholder="填写菜品类目"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="$emit('update:visible',false)" size="small">取 消</el-button>
      <el-button type="primary" @click="foodCheck()" size="small">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
  import api from '@/utils/api.js'

  export default {
    name: 'taskListDialog',
    props: ['visible', 'cateName', 'dialogType', 'cateId'],
    watch: {
      visible () {
        this.dialogVisible = this.visible
      },
      cateName () {
        this.cateNameV = this.cateName
      }
    },
    data () {
      return {
        dialogVisible: this.visible,
        cateNameV: ''
      }
    },
    created () {
    },
    methods: {
      foodCheck () {
        console.log()
        if (!this.cateNameV) {
          this.$message.error('请填写类目名称')
        } else {
          let url_ = api.cate_add
          let data_ = {
            name: this.cateNameV
          }
          if (this.dialogType === 'edit') {
            url_ = api.cate_edit
            data_.id = this.cateId
          }
          this.$post(url_, data_).then((response) => {
            if (response.code === 0) {
              this.$message({
                message: '编辑成功',
                type: 'success'
              })
              this.$emit('initPage', this.cateNameV)
              this.dialogVisible = false
              this.this.cateNameV = ''
            } else {
            }
          }).catch((err) => {
            console.log(err)
          })
        }
      }
    }
  }
</script>
<style>
  .cateBody {
    padding: 40px 0;
  }
</style>
